package NovelBar.service;

import NovelBar.dto.ChapterDto;
import NovelBar.entity.Chapter;
import NovelBar.dto.OneChapterInfo;
import NovelBar.mapper.ChapterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ChapterService {
    @Autowired
    private ChapterMapper chapterMapper;

    public Chapter loadNewChapterByBookId(Integer bookid) {
        return chapterMapper.loadNewChapterByBookId(bookid);
    }

    public void insertChapter(Chapter chapter) {
        Date date = new Date();
        SimpleDateFormat matter = new SimpleDateFormat("yyyy/MM/dd");
        chapter.setDate(matter.format(date).toString());
        chapterMapper.insertChapter(chapter);
    }
    public List<Chapter> getChapterByBookId(Integer bookId){
        return chapterMapper.getChapterByBookId(bookId);
    }

    public OneChapterInfo getOneChapterById(Integer chapterBookId,Integer bookId){
        return chapterMapper.getOneChapterById(chapterBookId,bookId);
    }

    public void updateVip(ChapterDto chapterDto) {
        chapterMapper.updateVip(chapterDto);
    }
}
